package br.univas.bean;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.primefaces.model.DualListModel;

import br.univas.dao.ActorDAO;
import br.univas.to.ActorTO;

@ManagedBean(name="actorBean")
@RequestScoped 
public class ActorBean implements Serializable{
	
	private static final long serialVersionUID = 1L;
	private ActorTO actorTo;
	private ActorDAO actorDao;
	private DualListModel<String> listActors;  
	//private List<String> actorSelected; 
	

	public ActorBean() {
		actorTo = new ActorTO();
		actorDao = new ActorDAO();
		
		 //Cities  
        List<String> actorsSource = actorDao.getAllActors();  
        List<String> actorsTarget = new ArrayList<String>();
                 
        listActors = new DualListModel<String>(actorsSource, actorsTarget); 
        //actorSelected = new ArrayList<String>();
	}
	
	/*public void selectTransfer(TransferEvent event) {
		actorSelected = "";
	    for (Object p : getListActors().getTarget()){
	    	actorSelected += p.toString() + " ";
	}
	}*/
	/*public void onTransfer(TransferEvent event) {  
        StringBuilder builder = new StringBuilder();  
        for(Object item : event.getItems()) {  
            builder.append(((Player) item).getName()).append("<br />");  
        }  */
	
	/*public List getListActorsSelected() {
		return this.actorSelected = listActors.getTarget();
	}*/
	public DualListModel<String> getListActors() {
		return listActors;
	}

	public void setListActors(DualListModel<String> listActors) {
		this.listActors = listActors;
	}

	
	
	
	/*CRUD*/
	public void saveActor(){
		if(this.actorDao.saveActorGraph(this.actorTo)){
			System.out.println("Ator cadastrado");
		}
		else{
			System.out.println("O ator não foi cadastrado");
		}
		
		//System.out.println(this.nome);
		//this.limpaCampos();
	}
	/*Responsavei pela transi��o Bean and To*/
	public ActorTO getActorTo() {
		return actorTo;
	}

	public void setActorTo(ActorTO actorTo) {
		this.actorTo = actorTo;
	}

	public ActorDAO getActorDao() {
		return actorDao;
	}

	public void setActorDao(ActorDAO actorDao) {
		this.actorDao = actorDao;
	}
	
	
	

}